#include "stdio.h"

#include "NUC900_GE.h"
//#include "myio.h"
#include "wbio.h"

#define INC_STEP  	4
#define INC_STEP_X 	4
#define INC_STEP_Y 	3

const int ColorTbl[3]={0xff0000, 0x00ff00, 0x0000ff};


///////////////////////////////////////////////////////////////////////////////
//
// Function: demo_line_draw()
//
///////////////////////////////////////////////////////////////////////////////
#if 1 //smf //cmn
void demo_line_draw()
{
  int x1, y1, x2, y2;
  int color, i;
  static idx = 0; // index to color table
  int scrwitch, scrheight;
  
  scrwitch = 320 - 1;
  scrheight = 240 -1;
  
  color = ColorTbl[idx++];
  if (idx==3) idx = 0;
    
  /*
  ** LCD 240 * 320
  ** 400/4 = 100 (INC_STEP=4) 
  */
  x1 = 0;
  y1 = 0;
  x2 = scrwitch;
  y2 = 0+1;
    
  for (i=0; i<80; i++)
  {
    draw_solid_line(x1, y1, x2, y2, color); 
    x1 += 4;
    y2 += 3;
  }

  color = ColorTbl[1];
  x1 = scrwitch;
  y1 = 0;
  x2 = scrwitch;
  y2 = scrheight;
  for (i=0; i<80; i++)
  {
	draw_solid_line(x1, y1, x2, y2, color); 
	y1 += 3;
	x2 -= 4;
  }

  color = ColorTbl[2];
  x1 = scrwitch;
  y1 = scrheight;
  x2 = 0;
  y2 = scrheight;
  for (i=0; i<80; i++)
  {
	draw_solid_line(x1, y1, x2, y2, color); 
 	x1 -= 4;
 	y2 -= 3;	
  }

  color = 0xFFFFFF;
  x1 = 0;
  y1 = scrheight;
  x2 = 0;
  y2 = 0;
  for (i=0; i<80; i++)
  {
	draw_solid_line(x1, y1, x2, y2, color); 
	y1 -= 3;
	x2 += 4;
  }
/*    // smf
  int x1, y1, x2, y2;
  int color, i;
  static idx = 0; // index to color table
  
  color = ColorTbl[idx++];
  if (idx==3) idx = 0;
    
  //
  // 400x400
  // 400/4 = 100 (INC_STEP=4) 
  //
  x1 = 0;
  y1 = 0;
  x2 = 127;
  y2 = 0+2;
    
  for (i=0; i<64; i++)
  {
    draw_solid_line(x1, y1, x2, y2, color); 
    x1 += 2;
    y2 += 2;
  }

  color = ColorTbl[1];
  x1 = 127;
  y1 = 0;
  x2 = 127;
  y2 = 159;
  for (i=0; i<64; i++)
  {
	draw_solid_line(x1, y1, x2, y2, color); 
	y1 += 2;
	x2 -= 2;
  }

  color = ColorTbl[2];
  x1 = 127;
  y1 = 159;
  x2 = 0;
  y2 = 159;
  for (i=0; i<64; i++)
  {
	draw_solid_line(x1, y1, x2, y2, color); 
 	x1 -= 2;
 	y2 -= 2;	
  }

  color = 0xFFFF00;
  x1 = 0;
  y1 = 159;
  x2 = 0;
  y2 = 0;
  for (i=0; i<64; i++)
  {
	draw_solid_line(x1, y1, x2, y2, color); 
	y1 -= 2;
	x2 += 2;
  }   
  */
}
#else
void demo_line_draw()
{
  int x1, y1, x2, y2;
  int color, i;
  static idx = 0; // index to color table
  
  color = ColorTbl[idx++];   // red, green, blue
  if (idx==3) idx = 0;
    
  /*
  ** 400x400
  ** 400/4 = 100 (INC_STEP=4) 
  */
  x1 = 120;
  y1 = 40;
  x2 = 520;
  y2 = 40+INC_STEP;
    
  for (i=0; i<100; i++)
  {
    draw_solid_line(x1, y1, x2, y2, color); 
    x1 += INC_STEP;
    y2 += INC_STEP;
  }

  x1 = 120;
  y1 = 40;
  x2 = 120+INC_STEP;
  y2 = 440;
  for (i=0; i<100; i++)
  {
	draw_solid_line(x1, y1, x2, y2, color); 
	y1 += INC_STEP;
	x2 += INC_STEP;
  }

  x1 = 520;
  y1 = 40;
  x2 = 520-INC_STEP;
  y2 = 440;
  for (i=0; i<100; i++)
  {
	draw_solid_line(x1, y1, x2, y2, color); 
 	y1 += INC_STEP;
	x2 -= INC_STEP;
  }

  x1 = 520;
  y1 = 40;
  x2 = 120;
  y2 = 40+INC_STEP;
  for (i=0; i<100; i++)
  {
	draw_solid_line(x1, y1, x2, y2, color); 
	x1 -= INC_STEP;
	y2 += INC_STEP;
  }
}
#endif

///////////////////////////////////////////////////////////////////////////////
//
// Function: demo_frame_draw()
//
///////////////////////////////////////////////////////////////////////////////
void demo_frame_draw()
{
  int x1, y1, x2, y2;
  int color, idx;
  
  clear_screen(0xffffff);
  
  idx = 0; // index to color table

#if 0  
  while (1)
  {
#endif  
    color = ColorTbl[idx++];
    if (idx==3)	idx = 0;
    
    x1 = 0;
    y1 = 0;
    x2 = GFX_WIDTH - 1;
    y2 = GFX_HEIGHT - 1;
    
    while ((x2 > x1) && (y2 > y1))
    {
      draw_frame(x1, y1, x2, y2, color, 0);
      x1 += INC_STEP_X;
      x2 -= INC_STEP_X;
      y1 += INC_STEP_Y;
      y2 -= INC_STEP_Y;
    }
#if 0	
  }
#endif  
}


